import {
  Entity,
  Column,
  PrimaryColumn,
  OneToOne,
  JoinColumn,
  OneToMany,
  ManyToMany
} from 'typeorm'
import { Login, Comment, Post } from './index'

@Entity()
export class User {
  @PrimaryColumn({ unique: true })
  id: string

  @Column({ length: 12, default: '' })
  nickname: string

  @Column({ default: 18 })
  age: number

  @Column({ default: 0 })
  sex: number

  @Column({ default: 'https://img.yzcdn.cn/vant/cat.jpeg' })
  url: string

  @OneToOne(() => Login, (item) => item.id)
  @JoinColumn()
  login: Login

  @OneToMany(() => Comment, (item) => item.id)
  @JoinColumn()
  content: Comment[]

  @ManyToMany(() => Post, (post) => post.like)
  like: Post[]

  @ManyToMany(() => Post, (post) => post.collection)
  collection: Post[]
}
